package com.aircms.common;

import java.io.Serializable;

/**
 * 接口返回统一格式
 * @param <T>
 */
public class ServerResponse<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;

    private ResponseCodeAndMsg responseCodeAndMsg=new ResponseCodeAndMsg();

    private ServerResponse(T data ,Integer code,String msg){
        this.data= data == "" ? null : data;
        this.code=code;
        this.msg=responseCodeAndMsg.getMap().get(code)+msg;
    }
    private ServerResponse(T data ,Integer code){
        this.data= data == "" ? null : data;
        this.code=code;
        this.msg= (String) responseCodeAndMsg.getMap().get(code);
    }
    private ServerResponse(T data ){
        this.data= data == "" ? null : data;
        this.msg= (String) responseCodeAndMsg.getMap().get(1);
        this.code=1;
    }

    private ServerResponse(){
        this.data= null;
        this.msg= (String) responseCodeAndMsg.getMap().get(1);
        this.code=1;
    }


    public int getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> ServerResponse<T> resResponse(T data, Integer code,String msg){
        return new ServerResponse<T>(data,code,msg);
    }

    public static <T> ServerResponse<T> resResponse(T data, Integer code){
        return new ServerResponse<T>(data,code);
    }

    public static <T> ServerResponse<T> resResponse(T data){
        return new ServerResponse<T>(data);
    }

    public static <T> ServerResponse<T> resResponse(){
        return new ServerResponse<T>();
    }



}
